 package cn.exrick.xboot.modules.content.dao;

 import cn.exrick.xboot.base.XbootBaseDao;
 import cn.exrick.xboot.modules.base.entity.Role;
 import cn.exrick.xboot.modules.content.entity.HontRole;
 import cn.exrick.xboot.modules.content.entity.HontVo.HontRoleLevelVo;
 import cn.exrick.xboot.modules.content.entity.HontVo.HontUserRolelevelVo;
 import org.springframework.data.jpa.repository.Query;

 import java.util.List;
 import java.util.Optional;


 /**
  * 测试数据处理层
  * @author Exrick
  */
 public interface HontRoleDao extends XbootBaseDao<HontRole, String> {

  /**
   * 获取默认角色
   * @param defaultRole
   * @return
   */
  List<HontRole> findByDefaultRole(Boolean defaultRole);

  @Override
  Optional<HontRole> findById(String s);


  HontRole findByName(String name);

  List<HontRole> findByNameLike(String name);

  @Query(value = "SELECT r.* FROM hont_user_role ur" +
          "      left JOIN hont_role r" +
          "      ON ur.hont_role_id = r.id" +
          "      WHERE hont_user_id = ?1" ,nativeQuery=true)
  HontRole findHontRoleByUserId(String userId);

  @Query(value = "SELECT new cn.exrick.xboot.modules.content.entity.HontVo.HontRoleLevelVo(ur.hontUserId, r.level) FROM HontRole r INNER JOIN HontUserRole ur on ur.hontRoleId = r.id")
  List<HontRoleLevelVo> findRoleLevelById();

 }